package com.deepfos.outreach.rest;

import com.alibaba.fastjson.JSONObject;
import com.deepfos.outreach.cache.RoutersInfoCache;
import com.deepfos.outreach.domain.CashFlowSlot;
import com.deepfos.outreach.util.ServletUtil;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;
import java.util.Objects;


@Slf4j
@RestController
public class FlowExecutorHandler {

    @Autowired
    private RoutersInfoCache ric;

    @Resource
    private FlowExecutor flowExecutor;

    @PostMapping("/cashFlow/push")
    public Object execute(HttpServletRequest request) throws IOException {
        JSONObject requestJson = ServletUtil.getRequestJson(request);
        LiteflowResponse<CashFlowSlot> cashFlowSlotLiteflowResponse = flowExecutor.execute2Resp("cashFlowPush", requestJson.get("cf_ids"), CashFlowSlot.class);
        return cashFlowSlotLiteflowResponse.getSlot().getResponseData();
    }

}
